package com.hyperzsoft.budget;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;


public class MainView extends Activity {
	
	static private String TAG = "MainView";
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		try {
			MenuInflater inflater = getMenuInflater();
			inflater.inflate(R.menu.main_menu, menu);
			return true;
		} catch (Exception e) {
			Log.e(TAG, e.getStackTrace().toString());
			return false;
		}
	}
	
//	public void loadDialog(int dialogType)
//	{
//		//setup dialog
//		Dialog dialog = new Dialog(this);
//		dialog.setContentView(R.layout.types_list);
//		dialog.setTitle("Edit Types");
//		dialog.setCancelable(true);
//		dialog.setOwnerActivity(this);
//		
//		new TypeEditDialog().onCreate(dialogType, dialog);
//		
//		dialog.show();
//	}
    
	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		Intent myIntent = new Intent();
		
		try {
			// Handle item selection
			switch (item.getItemId()) {
			case R.id.expense_type_list:
//				myIntent.setClassName("com.hyperzsoft.budget", "com.hyperzsoft.budget.ExpenseList");
//				startActivityForResult(myIntent, PICK_EXPENSE_TYPE_REQUEST);
//				
//				return true;
				
				return true;
			case R.id.quit:
				finish();
				return true;
			case R.id.extra:
				myIntent.putExtra("type_of", new DBProvider(getApplicationContext()).EXPENSE_TYPES);
				myIntent.setClassName("com.hyperzsoft.budget", "com.hyperzsoft.budget.EditTypes");
				startActivity(myIntent);
				return true;
			case R.id.create_db:
				new CreateData().createDefaultGroupsAndItems(getApplicationContext());
				return true;
			default:
				return super.onOptionsItemSelected(item);
			}
		} catch (Exception e) {
			Log.e(TAG, e.toString());
			return false;
		}
	}
	
	public void onActivityResult (int requestCode, int resultCode, Intent data) {
//		if (requestCode == PICK_EXPENSE_TYPE_REQUEST) {
//            if (resultCode == RESULT_OK) {
//                // A contact was picked.  Here we will just display it
//                // to the user.
//                //startActivity(new Intent(Intent.ACTION_VIEW, data));
//            }
//        }
	}
}
